package com.maopao;


import java.util.ArrayList;
import java.util.Arrays;

public class MaoPao {
    public static void main(String[] args) {
        int[] arr = {12,30,100,2,200,4};
        int[] arr1 = {2,100,20,30,120};

        Arrays.sort(arr1);
        System.out.println(arrToString(arr1));


        System.out.println(arrToString(compute(arr)));

        System.out.println(arrToString(arr));

    }

    public static String arrToString(int[] arr){

        StringBuffer str = new StringBuffer();
        str.append("[");

        for(int i=0;i<arr.length;i++){
            if(i==arr.length-1){
                str.append(arr[i]);
            }else{
                str.append(arr[i]+", ");
            }
        }
        str.append("]");
        return  str.toString();

    }

    public static int[] compute(int[] arr){
        for(int j=0;j<arr.length-1;j++){
            for(int i=0;i<arr.length-1-j;i++){
                if(arr[i+1] < arr[i]){
                    int temp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = temp;
                }
            }
        }
        return arr;
    }
}
